<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/page/common/commonPage.jsp"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>内容搜索</title>
    <link rel="stylesheet" type="text/css" href="${resourcesUrl}/common/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="${resourcesUrl}/common/css/font-awesome.min.css">
    <link rel="stylesheet" type="text/css" href="${resourcesUrl}/common/css/smartadmin-production.min.css">
</head>
<body>
    <%@ include file="/WEB-INF/page/common/header.jsp"%>
    <%@ include file="/WEB-INF/page/common/leftSideBar.jsp"%>

    <div id="main" role="main">
        <div id="ribbon">
            <ol class="breadcrumb">
                <li>首页</li>
                <li>内容管理</li>
                <li>内容搜索</li>
            </ol>
        </div>
        <div id="content">
            <div class="row">
                <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
                    <div class="jarviswidget">
                        <header>
                            <h2><i class="fa fa-search"></i> 内容搜索</h2>
                        </header>
                        <div class="widget-body">
                            <form id="searchForm" class="smart-form">
                                <fieldset>
                                    <div class="row">
                                        <section class="col col-3">
                                            <label class="label">所属栏目</label>
                                            <label class="select">
                                                <select name="columnId" class="form-control">
                                                    <option value="">全部</option>
                                                    <c:forEach items="${columns}" var="column">
                                                        <option value="${column.columnId}">
                                                            ${column.columnName}[${column.columnId}]
                                                        </option>
                                                    </c:forEach>
                                                </select>
                                                <i></i>
                                            </label>
                                        </section>
                                        <section class="col col-3">
                                            <label class="label">内容标识</label>
                                            <label class="input">
                                                <i class="icon-append fa fa-search"></i>
                                                <input type="text" name="contentMark" class="form-control">
                                            </label>
                                        </section>
                                        <section class="col col-3">
                                            <label class="label">内容发布人</label>
                                            <label class="input">
                                                <i class="icon-append fa fa-user"></i>
                                                <input type="text" name="createUser" class="form-control">
                                            </label>
                                        </section>
                                        <section class="col col-3">
                                            <label class="label">状态</label>
                                            <label class="select">
                                                <select name="status" class="form-control">
                                                    <option value="">全部</option>
                                                    <option value="1">开放</option>
                                                    <option value="0">停用</option>
                                                </select>
                                                <i></i>
                                            </label>
                                        </section>
                                    </div>
                                </fieldset>
                                <footer>
                                    <button type="submit" class="btn btn-primary">
                                        <i class="fa fa-search"></i> 搜索
                                    </button>
                                    <button type="reset" class="btn btn-default">
                                        <i class="fa fa-refresh"></i> 重置
                                    </button>
                                </footer>
                            </form>
                            
                            <hr>
                            
                            <table id="searchResult" class="table table-striped table-hover">
                                <thead>
                                    <tr>
                                        <th>内容标识</th>
                                        <th>所属栏目</th>
                                        <th>标题</th>
                                        <th>发布人</th>
                                        <th>发布时间</th>
                                        <th>状态</th>
                                        <th>操作</th>
                                    </tr>
                                </thead>
                                <tbody>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script src="${resourcesUrl}/common/js/jquery-1.8.2.min.js"></script>
    <script src="${resourcesUrl}/common/js/bootstrap/bootstrap.min.js"></script>
    <script src="${resourcesUrl}/common/js/plugin/jquery-validate/jquery.validate.min.js"></script>
    <script src="${resourcesUrl}/common/components/artDialog/dialog-min.js"></script>
    <script type="text/javascript">
        $(document).ready(function() {
            $("#searchForm").submit(function(e) {
                e.preventDefault();
                $.ajax({
                    url: '${base}/content/doSearch',
                    type: 'POST',
                    data: $(this).serialize(),
                    success: function(data) {
                        if(data.RET_CODE.toLowerCase() === 'success') {
                            var contents = data.RET_OBJ;
                            var tbody = $("#searchResult tbody");
                            tbody.empty();
                            
                            if(contents && contents.length > 0) {
                                $.each(contents, function(i, content) {
                                    var tr = $("<tr></tr>");
                                    tr.append("<td>" + content.contentMark + "</td>");
                                    tr.append("<td>" + content.columnId + "</td>");
                                    tr.append("<td>" + content.title + "</td>");
                                    tr.append("<td>" + content.createUser + "</td>");
                                    tr.append("<td>" + content.createTime + "</td>");
                                    tr.append("<td>" + (content.status === '1' ? '开放' : '停用') + "</td>");
                                    tr.append("<td>" +
                                        "<button type='button' class='btn btn-primary btn-xs' onclick='window.location.href=\"${base}/content/edit?contentId=" + content.contentId + "\"'>" +
                                        "<i class='fa fa-pencil'></i> 编辑</button> " +
                                        "</td>");
                                    tbody.append(tr);
                                });
                            } else {
                                tbody.append("<tr><td colspan='7' class='text-center'>暂无数据</td></tr>");
                            }
                        } else {
                            dialog({
                                title: '提示',
                                content: data.RET_OBJ || '搜索失败',
                                ok: function() {}
                            }).showModal();
                        }
                    }
                });
            });
        });
    </script>
    <%@ include file="/WEB-INF/page/common/footer.jsp"%>
</body>
</html> 